package cn.bb.gulimall.order.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import cn.bb.gulimall.order.feign.OrderFeignToCouponService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import cn.bb.gulimall.order.entity.OrderEntity;
import cn.bb.gulimall.order.service.OrderService;
import cn.bb.common.utils.PageUtils;
import cn.bb.common.utils.R;



/**
 * 订单
 *
 * @author sharpbb
 * @email 1029922944@gmail.com
 * @date 2020-11-25 20:13:23
 */
@RefreshScope
@RestController
@RequestMapping("coupon/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @Autowired
    private OrderFeignToCouponService orderFeignToCouponService;
    @Value("${config.name}")
    String name;
//
//    @Value("${order.password}")
//    String password;

    @GetMapping("/look")
    public R getCoupon(){
       return orderFeignToCouponService.look();
    }


    @GetMapping("/test")
    public R test(){
        return new R().put("config",name);
    }





    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("coupon:order:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("coupon:order:info")
    public R info(@PathVariable("id") Long id){
		OrderEntity order = orderService.getById(id);

        return R.ok().put("order", order);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("coupon:order:save")
    public R save(@RequestBody OrderEntity order){
		orderService.save(order);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("coupon:order:update")
    public R update(@RequestBody OrderEntity order){
		orderService.updateById(order);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("coupon:order:delete")
    public R delete(@RequestBody Long[] ids){
		orderService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
